//
// Created by lester on 2023/12/21.
//

#ifndef TEST_OUTPUTSTREAM_H
#define TEST_OUTPUTSTREAM_H
#include "LengthBuffer.h"
class OutputStream{
public:
    friend class Logger;
    ~OutputStream() = default;
    OutputStream() = default;
    OutputStream& operator <<(uint8_t value);
    OutputStream& operator <<(uint16_t value);
    OutputStream& operator <<(uint32_t value);
    OutputStream& operator <<(uint64_t value);
    OutputStream& operator <<(int8_t value);
    OutputStream& operator <<(int16_t value);
    OutputStream& operator <<(int32_t value);
    OutputStream& operator <<(int64_t value);
    OutputStream& operator <<(float value);
    OutputStream& operator <<(double value);
    OutputStream& operator <<(const std::string& value);
private:
    SmallBuffer  buffer_;
};

OutputStream& OutputStream::operator<<(int value) {
    std::string stringValue = std::to_string(value);
    buffer_.Append(stringValue.c_str(), stringValue.size());
    return *this;
}

OutputStream& OutputStream::operator<<(uint8_t value) {
    std::string stringValue = std::to_string(value);
    buffer_.Append(stringValue.c_str(), stringValue.size());
    return *this;
}

OutputStream& OutputStream::operator<<(uint16_t value) {
    std::string stringValue = std::to_string(value);
    buffer_.Append(stringValue.c_str(), stringValue.size());
    return *this;
}

OutputStream& OutputStream::operator<<(uint32_t value) {
    std::string stringValue = std::to_string(value);
    buffer_.Append(stringValue.c_str(), stringValue.size());
    return *this;
}

OutputStream& OutputStream::operator<<(uint64_t value) {
    std::string stringValue = std::to_string(value);
    buffer_.Append(stringValue.c_str(), stringValue.size());
    return *this;
}

OutputStream& OutputStream::operator<<(int8_t value) {
    std::string stringValue = std::to_string(value);
    buffer_.Append(stringValue.c_str(), stringValue.size());
    return *this;;
}

OutputStream& OutputStream::operator<<(int16_t value) {
    std::string stringValue = std::to_string(value);
    buffer_.Append(stringValue.c_str(), stringValue.size());
    return *this;
}

OutputStream& OutputStream::operator<<(int64_t value) {
    std::string stringValue = std::to_string(value);
    buffer_.Append(stringValue.c_str(), stringValue.size());
    return *this;
}

OutputStream& OutputStream::operator<<(float value) {
    std::string stringValue = std::to_string(value);
    buffer_.Append(stringValue.c_str(), stringValue.size());
    return *this;
}

OutputStream &OutputStream::operator<<(double value) {
    std::string stringValue = std::to_string(value);
    buffer_.Append(stringValue.c_str(), stringValue.size());
    return *this;
}

OutputStream &OutputStream::operator<<(const std::string &value) {
    buffer_.Append(value.c_str(),value.size());
    return *this;
}
#endif //TEST_OUTPUTSTREAM_H
